home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / megasys1.h < prev    next >
Text File  |  2000-04-23  |  13KB  |  378 lines

  1. /***************************************************************************
  2.  
  3.                         -= Jaleco Mega System 1 =-
  4.  
  5.                 driver by    Luca Elia (eliavit@unina.it)
  6.  
  7.  
  8.     This file contains definitions used across multiple megasys1
  9.     and non megasys1 Jaleco games:
  10.  
  11.     * Gfx layouts
  12.     * Input ports
  13.     * Read and write errors logging
  14.     * Scrolling layers handling
  15.  
  16. ***************************************************************************/
  17.  
  18.  
  19. /***************************************************************************
  20.  
  21.                              Sound Chips Access
  22.  
  23. ***************************************************************************/
  24.  
  25. WRITE_HANDLER( ms_soundlatch_w );
  26. WRITE_HANDLER( ms_soundlatch2_w );
  27. WRITE_HANDLER( ms_YM2151_register_port_0_w );
  28. WRITE_HANDLER( ms_YM2151_data_port_0_w );
  29. WRITE_HANDLER( ms_OKIM6295_data_0_w );
  30. WRITE_HANDLER( ms_OKIM6295_data_1_w );
  31.  
  32.  
  33. /***************************************************************************
  34.  
  35.                              Code Decryption
  36.  
  37. ***************************************************************************/
  38.  
  39. /*
  40.  This macro is used to decrypt the code roms:
  41.  the first parameter is the encrypted word, the other parameters specify
  42.  the bits layout to build the word in clear from the encrypted one
  43. */
  44. #define BITSWAP(_x,_f,_e,_d,_c,_b,_a,_9,_8,_7,_6,_5,_4,_3,_2,_1,_0)\
  45.         (((_x & (1 << _0))?(1<<0x0):0) + \
  46.          ((_x & (1 << _1))?(1<<0x1):0) + \
  47.          ((_x & (1 << _2))?(1<<0x2):0) + \
  48.          ((_x & (1 << _3))?(1<<0x3):0) + \
  49.          ((_x & (1 << _4))?(1<<0x4):0) + \
  50.          ((_x & (1 << _5))?(1<<0x5):0) + \
  51.          ((_x & (1 << _6))?(1<<0x6):0) + \
  52.          ((_x & (1 << _7))?(1<<0x7):0) + \
  53.          ((_x & (1 << _8))?(1<<0x8):0) + \
  54.          ((_x & (1 << _9))?(1<<0x9):0) + \
  55.          ((_x & (1 << _a))?(1<<0xa):0) + \
  56.          ((_x & (1 << _b))?(1<<0xb):0) + \
  57.          ((_x & (1 << _c))?(1<<0xc):0) + \
  58.          ((_x & (1 << _d))?(1<<0xd):0) + \
  59.          ((_x & (1 << _e))?(1<<0xe):0) + \
  60.          ((_x & (1 << _f))?(1<<0xf):0))
  61.  
  62.  
  63. void astyanax_rom_decode(int cpu);
  64. void phantasm_rom_decode(int cpu);
  65. void rodland_rom_decode(int cpu);
  66.  
  67.  
  68. /***************************************************************************
  69.  
  70.                                 Gfx Layouts
  71.  
  72. ***************************************************************************/
  73.  
  74.  
  75. /* 8x8x4 layout - straightforward arrangement */
  76. #define MEGASYS1_LAYOUT_8x8(_name_,_romsize_)\
  77. static struct GfxLayout _name_ =\
  78. {\
  79.     8,8,\
  80.     (_romsize_)*8/(8*8*4),\
  81.     4,\
  82.     {0, 1, 2, 3},\
  83.     {0*4,1*4,2*4,3*4,4*4,5*4,6*4,7*4},\
  84.     {0*32,1*32,2*32,3*32,4*32,5*32,6*32,7*32},\
  85.     8*8*4\
  86. };
  87.  
  88.  
  89. /* 16x16x4 layout - straightforward arrangement */
  90. #define MEGASYS1_LAYOUT_16x16(_name_,_romsize_) \
  91. static struct GfxLayout _name_ =\
  92. {\
  93.     16,16,\
  94.     (_romsize_)*8/(16*16*4),\
  95.     4,\
  96.     {0, 1, 2, 3},\
  97.     {0*4,1*4,2*4,3*4,4*4,5*4,6*4,7*4, \
  98.      8*4,9*4,10*4,11*4,12*4,13*4,14*4,15*4}, \
  99.     {0*64,1*64,2*64,3*64,4*64,5*64,6*64,7*64,\
  100.      8*64,9*64,10*64,11*64,12*64,13*64,14*64,15*64},\
  101.     16*16*4\
  102. };
  103.  
  104.  
  105. /* 16x16x4 layout - formed by four 8x8x4 tiles  */
  106. #define MEGASYS1_LAYOUT_16x16_QUAD(_name_,_romsize_)\
  107. static struct GfxLayout _name_ =\
  108. {\
  109.     16,16,\
  110.     (_romsize_)*8/(16*16*4),\
  111.     4,\
  112.     {0, 1, 2, 3},\
  113.     {0*4,1*4,2*4,3*4,4*4,5*4,6*4,7*4,\
  114.      0*4+32*16,1*4+32*16,2*4+32*16,3*4+32*16,4*4+32*16,5*4+32*16,6*4+32*16,7*4+32*16},\
  115.     {0*32,1*32,2*32,3*32,4*32,5*32,6*32,7*32,\
  116.      8*32,9*32,10*32,11*32,12*32,13*32,14*32,15*32},\
  117.     16*16*4\
  118. };
  119.  
  120.  
  121.  
  122. /***************************************************************************
  123.  
  124.                                 Input Ports
  125.  
  126. ***************************************************************************/
  127.  
  128.  
  129. /* IN0 - COINS */
  130. #define COINS \
  131.     PORT_START\
  132.     PORT_BIT(  0x01, IP_ACTIVE_LOW, IPT_START1 )\
  133.     PORT_BIT(  0x02, IP_ACTIVE_LOW, IPT_START2 )\
  134.     PORT_BIT(  0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  135.     PORT_BIT(  0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  136.     PORT_BIT(  0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  137.     PORT_BIT(  0x20, IP_ACTIVE_LOW, IPT_COIN3 )\
  138.     PORT_BIT(  0x40, IP_ACTIVE_LOW, IPT_COIN1 )\
  139.     PORT_BIT(  0x80, IP_ACTIVE_LOW, IPT_COIN2 )
  140.  
  141. /* IN1/3 - PLAYER 1/2 */
  142. #define JOY_4BUTTONS(_flag_) \
  143.     PORT_START\
  144.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | _flag_ )\
  145.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | _flag_ )\
  146.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | _flag_ )\
  147.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | _flag_ )\
  148.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | _flag_ )\
  149.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | _flag_ )\
  150.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | _flag_ )\
  151.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 | _flag_ )
  152.  
  153. #define JOY_3BUTTONS(_flag_) \
  154.     PORT_START\
  155.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | _flag_ )\
  156.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | _flag_ )\
  157.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | _flag_ )\
  158.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | _flag_ )\
  159.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | _flag_ )\
  160.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | _flag_ )\
  161.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | _flag_ )\
  162.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  163.  
  164. #define JOY_2BUTTONS(_flag_) \
  165.     PORT_START\
  166.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | _flag_ )\
  167.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | _flag_ )\
  168.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | _flag_ )\
  169.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | _flag_ )\
  170.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | _flag_ )\
  171.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | _flag_ )\
  172.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  173.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  174.  
  175. /* IN2 - RESERVE */
  176. #define RESERVE \
  177.     PORT_START\
  178.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN ) /* Reserve 1P */\
  179.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  180.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  181.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  182.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) /* Reserve 2P */\
  183.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  184.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )\
  185.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  186.  
  187. /* IN4 - Coinage DSWs */
  188. //    1]    01-41 02-31 03-21 07-11 06-12 05-13 04-14 00-FC    * 2
  189. //    2]    04-31 02-21 07-11 03-12 05-13 01-14 06-15 00-FC
  190. //        00-41 20-31 10-21 38-11 18-12 28-13 08-14 30-15
  191.  
  192.  
  193. #define COINAGE_6BITS \
  194.     PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) )\
  195.     PORT_DIPSETTING(    0x04, DEF_STR( 3C_1C ) )\
  196.     PORT_DIPSETTING(    0x02, DEF_STR( 2C_1C ) )\
  197.     PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )\
  198.     PORT_DIPSETTING(    0x03, DEF_STR( 1C_2C ) )\
  199.     PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )\
  200.     PORT_DIPSETTING(    0x01, DEF_STR( 1C_4C ) )\
  201.     PORT_DIPSETTING(    0x06, DEF_STR( 1C_5C ) )\
  202.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )\
  203.     PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coin_B ) )\
  204.     PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )\
  205.     PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )\
  206.     PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )\
  207.     PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )\
  208.     PORT_DIPSETTING(    0x18, DEF_STR( 1C_2C ) )\
  209.     PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )\
  210.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_4C ) )\
  211.     PORT_DIPSETTING(    0x30, DEF_STR( 1C_5C ) )\
  212.  
  213. #define COINAGE_6BITS_2 \
  214.     PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) )\
  215.     PORT_DIPSETTING(    0x01, DEF_STR( 4C_1C ) )\
  216.     PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )\
  217.     PORT_DIPSETTING(    0x03, DEF_STR( 2C_1C ) )\
  218.     PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )\
  219.     PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )\
  220.     PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )\
  221.     PORT_DIPSETTING(    0x04, DEF_STR( 1C_4C ) )\
  222.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )\
  223.     PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coin_B ) )\
  224.     PORT_DIPSETTING(    0x08, DEF_STR( 4C_1C ) )\
  225.     PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) )\
  226.     PORT_DIPSETTING(    0x18, DEF_STR( 2C_1C ) )\
  227.     PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )\
  228.     PORT_DIPSETTING(    0x30, DEF_STR( 1C_2C ) )\
  229.     PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )\
  230.     PORT_DIPSETTING(    0x20, DEF_STR( 1C_4C ) )\
  231.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )\
  232.  
  233. #define COINAGE_8BITS \
  234.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )\
  235.     PORT_DIPSETTING(    0x07, DEF_STR( 4C_1C ) )\
  236.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ) )\
  237.     PORT_DIPSETTING(    0x09, DEF_STR( 2C_1C ) )\
  238.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )\
  239. /*    PORT_DIPSETTING(    0x05, DEF_STR( 1C_1C ) )*/    \
  240. /*    PORT_DIPSETTING(    0x04, DEF_STR( 1C_1C ) )*/    \
  241. /*    PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )*/    \
  242. /*    PORT_DIPSETTING(    0x02, DEF_STR( 1C_1C ) )*/    \
  243. /*    PORT_DIPSETTING(    0x01, DEF_STR( 1C_1C ) )*/    \
  244.     PORT_DIPSETTING(    0x06, DEF_STR( 2C_3C ) )\
  245.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )\
  246.     PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )\
  247.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )\
  248.     PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )\
  249.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )\
  250.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )\
  251.     PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )\
  252.     PORT_DIPSETTING(    0x70, DEF_STR( 4C_1C ) )\
  253.     PORT_DIPSETTING(    0x80, DEF_STR( 3C_1C ) )\
  254.     PORT_DIPSETTING(    0x90, DEF_STR( 2C_1C ) )\
  255.     PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )\
  256. /*    PORT_DIPSETTING(    0x50, DEF_STR( 1C_1C ) )*/    \
  257. /*    PORT_DIPSETTING(    0x40, DEF_STR( 1C_1C ) )*/    \
  258. /*    PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )*/    \
  259. /*    PORT_DIPSETTING(    0x20, DEF_STR( 1C_1C ) )*/    \
  260. /*    PORT_DIPSETTING(    0x10, DEF_STR( 1C_1C ) )*/    \
  261.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_3C ) )\
  262.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )\
  263.     PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )\
  264.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )\
  265.     PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )\
  266.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ) )\
  267.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  268.  
  269.  
  270. /***************************************************************************
  271.  
  272.                         Read and Write Errors Logging
  273.  
  274. ***************************************************************************/
  275.  
  276.  
  277. #ifdef MAME_DEBUG
  278. #define SHOW_READ_ERROR(_format_,_offset_)\
  279. {\
  280.     char buf[80];\
  281.     sprintf(buf,_format_,_offset_);\
  282.     usrintf_showmessage(buf);\
  283.     logerror("CPU #0 PC %06X : Warning, %s\n",cpu_get_pc(), buf); \
  284. }
  285.  
  286. #define SHOW_WRITE_ERROR(_format_,_offset_,_data_)\
  287. {\
  288.     char buf[80];\
  289.     sprintf(buf,_format_,_offset_,_data_);\
  290.     usrintf_showmessage(buf);\
  291.     logerror("CPU #0 PC %06X : Warning, %s\n",cpu_get_pc(), buf); \
  292. }
  293.  
  294. #else
  295.  
  296. #define SHOW_READ_ERROR(_format_,_offset_)\
  297. {\
  298.     char buf[80];\
  299.     sprintf(buf,_format_,_offset_);\
  300.     logerror("CPU #0 PC %06X : Warning, %s\n",cpu_get_pc(), buf);\
  301. }
  302.  
  303. #define SHOW_WRITE_ERROR(_format_,_offset_,_data_)\
  304. {\
  305.     char buf[80];\
  306.     sprintf(buf,_format_,_offset_,_data_); \
  307.     logerror("CPU #0 PC %06X : Warning, %s\n",cpu_get_pc(), buf); \
  308. }
  309.  
  310. #endif
  311.  
  312.  
  313. /***************************************************************************
  314.  
  315.                         Scrolling Layers Handling
  316.  
  317. ***************************************************************************/
  318.  
  319. /* Variables */
  320. extern struct tilemap *megasys1_tmap_0, *megasys1_tmap_1, *megasys1_tmap_2;
  321. extern unsigned char *megasys1_scrollram_0, *megasys1_scrollram_1, *megasys1_scrollram_2;
  322. extern unsigned char *megasys1_objectram, *megasys1_vregs, *megasys1_ram;
  323. extern int megasys1_scroll_flag[3], megasys1_scrollx[3], megasys1_scrolly[3], megasys1_pages_per_tmap_x[3], megasys1_pages_per_tmap_y[3];
  324. extern int megasys1_active_layers, megasys1_sprite_bank;
  325. extern int megasys1_screen_flag, megasys1_sprite_flag;
  326. extern int megasys1_bits_per_color_code;
  327. extern int megasys1_8x8_scroll_0_factor, megasys1_16x16_scroll_0_factor;
  328. extern int megasys1_8x8_scroll_1_factor, megasys1_16x16_scroll_1_factor;
  329. extern int megasys1_8x8_scroll_2_factor, megasys1_16x16_scroll_2_factor;
  330.  
  331.  
  332. /* Functions */
  333. int  megasys1_vh_start(void);
  334.  
  335. READ_HANDLER( megasys1_scrollram_0_r );
  336. READ_HANDLER( megasys1_scrollram_1_r );
  337. READ_HANDLER( megasys1_scrollram_2_r );
  338.  
  339. WRITE_HANDLER( megasys1_scrollram_0_w );
  340. WRITE_HANDLER( megasys1_scrollram_1_w );
  341. WRITE_HANDLER( megasys1_scrollram_2_w );
  342.  
  343. void megasys1_scroll_0_flag_w(int data);
  344. void megasys1_scroll_1_flag_w(int data);
  345. void megasys1_scroll_2_flag_w(int data);
  346.  
  347.  
  348. #define MEGASYS1_VREG_FLAG(_n_) \
  349.         megasys1_scroll_##_n_##_flag_w(new_data); \
  350.         if (megasys1_tmap_##_n_ == 0) SHOW_WRITE_ERROR("vreg %04X <- %04X NO MEMORY FOR SCREEN",offset,data);
  351.  
  352. #define MEGASYS1_VREG_SCROLL(_n_, _dir_)    megasys1_scroll##_dir_[_n_] = new_data;
  353.  
  354.  
  355. #define MEGASYS1_TMAP_SET_SCROLL(_n_) \
  356.     if (megasys1_tmap_##_n_) \
  357.     { \
  358.         tilemap_set_scrollx(megasys1_tmap_##_n_, 0, megasys1_scrollx[_n_]); \
  359.         tilemap_set_scrolly(megasys1_tmap_##_n_, 0, megasys1_scrolly[_n_]); \
  360.     }
  361.  
  362. #define MEGASYS1_TMAP_UPDATE(_n_) \
  363.     if ( (megasys1_tmap_##_n_) && (megasys1_active_layers & (1 << _n_) ) ) \
  364.         tilemap_update(megasys1_tmap_##_n_);
  365.  
  366.  
  367. #define MEGASYS1_TMAP_RENDER(_n_) \
  368.     if ( (megasys1_tmap_##_n_) && (megasys1_active_layers & (1 << _n_) ) )\
  369.         tilemap_render(megasys1_tmap_##_n_);
  370.  
  371.  
  372. #define MEGASYS1_TMAP_DRAW(_n_) \
  373.     if ( (megasys1_tmap_##_n_) && (megasys1_active_layers & (1 << _n_) ) ) \
  374.     { \
  375.         tilemap_draw(bitmap, megasys1_tmap_##_n_, flag ); \
  376.         flag = 0; \
  377.     }
  378.